package nickname

import (
	"github.com/flipped-aurora/gin-vue-admin/server/global"
	"github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
	"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
	"github.com/flipped-aurora/gin-vue-admin/server/model/nickname"
	nicknameReq "github.com/flipped-aurora/gin-vue-admin/server/model/nickname/request"
	"github.com/flipped-aurora/gin-vue-admin/server/service"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

type NicknamesApi struct {
}

var nicknamesService = service.ServiceGroupApp.NicknameServiceGroup.NicknamesService

// CreateNicknames 创建Nicknames
// @Tags Nicknames
// @Summary 创建Nicknames
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body nickname.Nicknames true "创建Nicknames"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /nicknames/createNicknames [post]
func (nicknamesApi *NicknamesApi) CreateNicknames(c *gin.Context) {
	var nicknames nickname.Nicknames
	_ = c.ShouldBindJSON(&nicknames)
	if err := nicknamesService.CreateNicknames(nicknames); err != nil {
		global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// DeleteNicknames 删除Nicknames
// @Tags Nicknames
// @Summary 删除Nicknames
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body nickname.Nicknames true "删除Nicknames"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /nicknames/deleteNicknames [delete]
func (nicknamesApi *NicknamesApi) DeleteNicknames(c *gin.Context) {
	var nicknames nickname.Nicknames
	_ = c.ShouldBindJSON(&nicknames)
	if err := nicknamesService.DeleteNicknames(nicknames); err != nil {
		global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// DeleteNicknamesByIds 批量删除Nicknames
// @Tags Nicknames
// @Summary 批量删除Nicknames
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除Nicknames"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /nicknames/deleteNicknamesByIds [delete]
func (nicknamesApi *NicknamesApi) DeleteNicknamesByIds(c *gin.Context) {
	var IDS request.IdsReq
	_ = c.ShouldBindJSON(&IDS)
	if err := nicknamesService.DeleteNicknamesByIds(IDS); err != nil {
		global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// UpdateNicknames 更新Nicknames
// @Tags Nicknames
// @Summary 更新Nicknames
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body nickname.Nicknames true "更新Nicknames"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /nicknames/updateNicknames [put]
func (nicknamesApi *NicknamesApi) UpdateNicknames(c *gin.Context) {
	var nicknames nickname.Nicknames
	_ = c.ShouldBindJSON(&nicknames)
	if err := nicknamesService.UpdateNicknames(nicknames); err != nil {
		global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindNicknames 用id查询Nicknames
// @Tags Nicknames
// @Summary 用id查询Nicknames
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query nickname.Nicknames true "用id查询Nicknames"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /nicknames/findNicknames [get]
func (nicknamesApi *NicknamesApi) FindNicknames(c *gin.Context) {
	var nicknames nickname.Nicknames
	_ = c.ShouldBindQuery(&nicknames)
	if renicknames, err := nicknamesService.GetNicknames(nicknames.ID); err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"renicknames": renicknames}, c)
	}
}

// GetNicknamesList 分页获取Nicknames列表
// @Tags Nicknames
// @Summary 分页获取Nicknames列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query nicknameReq.NicknamesSearch true "分页获取Nicknames列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /nicknames/getNicknamesList [get]
func (nicknamesApi *NicknamesApi) GetNicknamesList(c *gin.Context) {
	var pageInfo nicknameReq.NicknamesSearch
	_ = c.ShouldBindQuery(&pageInfo)
	if list, total, err := nicknamesService.GetNicknamesInfoList(pageInfo); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, "获取成功", c)
	}
}

// NickNamesCreate 创建Nicknames
// @Tags Nicknames
// @Router /nicknames/create [post]
func (nicknamesApi *NicknamesApi) NickNamesCreate(c *gin.Context) {

}

// NickNamesGet 获取Nicknames
// @Tags Nicknames
// @Router /nicknames/get [get]
func (nicknamesApi *NicknamesApi) NickNamesGet(c *gin.Context) {

}
